package com.justnow;

/**
 * @author justnow
 * Created on 2020-09-23
 * Description
 */
public class GenShuixue02 {

    static Node getCommon(Node headA, Node headB) {
        Node nodeA = headA, nodeB = headB;
        while (nodeA != nodeB) {
            if (nodeA != null) {
                nodeA = nodeA.next;
            } else {
                nodeA = headB;
            }

            if (nodeB != null) {
                nodeB = nodeB.next;
            } else {
                nodeB = headA;
            }
        }
        return nodeA;
    }
}

class Node {
    int val;
    Node next;
}
